package org.example.struct.array;

import java.util.HashMap;
import java.util.Map;

/**
 * @author liyishan
 * @date 2023/12/4 09:49
 * @apiNote
 */

public class Test00136SingleNumber {

    public static void main(String[] args) {
        int[] nums = {1,1,2,2,4};
        System.out.println(test(nums));
    }

    public int singleNumber(int[] nums) {
        int res = 0;
        for(int num : nums){
            res ^= num;
        }
        return res;
    }

    public static int test(int[] nums){
        Map<Integer,Integer> map = new HashMap<>();
        for(Integer i: nums){
            map.put(i, map.getOrDefault(i, 0) + 1);
        }
        for(Integer i: map.keySet()){
            Integer count = map.get(i);
            if(count == 1) {
                return i;
            }
        }
        return -1;
    }
}
